package view;

import java.awt.Color;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import util.Comandos;
import controller.MasaController;
import java.awt.Font;
import javax.swing.JButton;


public class MasaFrame extends JDialog {

	private static final long serialVersionUID = 1L;
	private JLabel jLabel0;
	private JLabel jLabel1;
	private JTextField pesoTextField;
	private JTextField alturaTextField;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel resultadoLabel;
	private JSeparator jSeparator0;
	private JSeparator jSeparator1;
	private JLabel jLabel6;
	private JLabel jLabel7;
	private JLabel jLabel8;
	private JLabel jLabel9;
	private JLabel jLabel10;
	private JLabel jLabel11;
	private JLabel jLabel12;
	private JLabel jLabel13;
	private JLabel jLabel14;
	private JLabel jLabel15;
	private JLabel jLabel16;
	private JLabel jLabel19;
	private JLabel jLabel18;
	private JLabel jLabel17;
	private JLabel jLabel25;
	private JLabel jLabel26;
	private JLabel jLabel28;
	private JLabel jLabel29;
	private JLabel jLabel27;
	private JLabel jLabel20;
	private JLabel jLabel21;
	private JLabel jLabel22;
	private JLabel jLabel23;
	private JLabel jLabel24;
	private JLabel jLabel30;
	private JButton btnCap;
	
	public MasaFrame(PrincipalFrame principal) {
		setResizable(false);
		initComponents();
	}

	private void initComponents() {
		setTitle("Masa Corporal");
		getContentPane().setLayout(null);
		getContentPane().add(getJLabel0());
		getContentPane().add(getJLabel1());
		getContentPane().add(getJLabel4());
		getContentPane().add(getJSeparator0());
		getContentPane().add(getJSeparator1());
		getContentPane().add(getJLabel6());
		getContentPane().add(getJLabel7());
		getContentPane().add(getJLabel9());
		getContentPane().add(getJLabel10());
		getContentPane().add(getJLabel11());
		getContentPane().add(getJLabel12());
		getContentPane().add(getJLabel13());
		getContentPane().add(getJLabel14());
		getContentPane().add(getJLabel15());
		getContentPane().add(getJLabel16());
		getContentPane().add(getJLabel18());
		getContentPane().add(getJLabel17());
		getContentPane().add(getJLabel25());
		getContentPane().add(getJLabel26());
		getContentPane().add(getJLabel28());
		getContentPane().add(getJLabel27());
		getContentPane().add(getJLabel29());
		getContentPane().add(getJLabel8());
		getContentPane().add(getJLabel19());
		getContentPane().add(getJLabel30());
		getContentPane().add(getJLabel5());
		getContentPane().add(getJLabel2());
		getContentPane().add(getJLabel3());
		getContentPane().add(getJTextField0());
		getContentPane().add(getJTextField1());
		getContentPane().add(getJLabel21());
		getContentPane().add(getJLabel22());
		getContentPane().add(getJLabel23());
		getContentPane().add(getJLabel24());
		getContentPane().add(getJLabel20());
		getContentPane().add(getBtnCap());
		setSize(1154, 566);
	}

	private JLabel getJLabel30() {
		if (jLabel30 == null) {
			jLabel30 = new JLabel();
			jLabel30.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel30.setBounds(215, 475, 195, 25);
			jLabel30.setText("Mórbida o Masiva");
		}
		return jLabel30;
	}

	private JLabel getJLabel24() {
		if (jLabel24 == null) {
			jLabel24 = new JLabel();
			jLabel24.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel24.setBounds(571, 438, 124, 25);
			jLabel24.setText("30 ó más");
		}
		return jLabel24;
	}

	private JLabel getJLabel23() {
		if (jLabel23 == null) {
			jLabel23 = new JLabel();
			jLabel23.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel23.setBounds(571, 384, 61, 25);
			jLabel23.setText("20");
		}
		return jLabel23;
	}

	private JLabel getJLabel22() {
		if (jLabel22 == null) {
			jLabel22 = new JLabel();
			jLabel22.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel22.setBounds(571, 335, 44, 25);
			jLabel22.setText("10");
		}
		return jLabel22;
	}

	private JLabel getJLabel21() {
		if (jLabel21 == null) {
			jLabel21 = new JLabel();
			jLabel21.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel21.setBounds(571, 285, 44, 25);
			jLabel21.setText("0");
		}
		return jLabel21;
	}

	private JLabel getJLabel20() {
		if (jLabel20 == null) {
			jLabel20 = new JLabel();
			jLabel20.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel20.setBounds(571, 234, 155, 25);
			jLabel20.setText("-10");
		}
		return jLabel20;
	}

	private JLabel getJLabel27() {
		if (jLabel27 == null) {
			jLabel27 = new JLabel();
			jLabel27.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel27.setBounds(823, 335, 159, 25);
			jLabel27.setText("Sobrepeso");
		}
		return jLabel27;
	}

	private JLabel getJLabel29() {
		if (jLabel29 == null) {
			jLabel29 = new JLabel();
			jLabel29.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel29.setBounds(823, 438, 176, 25);
			jLabel29.setText("Obesidad Mórbida");
		}
		return jLabel29;
	}

	private JLabel getJLabel28() {
		if (jLabel28 == null) {
			jLabel28 = new JLabel();
			jLabel28.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel28.setBounds(823, 384, 282, 25);
			jLabel28.setText("Obesidad o sobrepeso severo");
		}
		return jLabel28;
	}

	private JLabel getJLabel26() {
		if (jLabel26 == null) {
			jLabel26 = new JLabel();
			jLabel26.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel26.setBounds(823, 285, 159, 25);
			jLabel26.setText("Peso Saludable");
		}
		return jLabel26;
	}

	private JLabel getJLabel25() {
		if (jLabel25 == null) {
			jLabel25 = new JLabel();
			jLabel25.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel25.setBounds(823, 234, 159, 25);
			jLabel25.setText("Delgadez");
		}
		return jLabel25;
	}

	private JLabel getJLabel17() {
		if (jLabel17 == null) {
			jLabel17 = new JLabel();
			jLabel17.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel17.setBounds(215, 336, 216, 25);
			jLabel17.setText("Sobrepeso (grado 1)");
		}
		return jLabel17;
	}

	private JLabel getJLabel18() {
		if (jLabel18 == null) {
			jLabel18 = new JLabel();
			jLabel18.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel18.setBounds(215, 385, 195, 25);
			jLabel18.setText("Sobrepeso (grado 2)");
		}
		return jLabel18;
	}

	private JLabel getJLabel19() {
		if (jLabel19 == null) {
			jLabel19 = new JLabel();
			jLabel19.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel19.setBounds(215, 439, 195, 25);
			jLabel19.setText("Sobrepeso (grado 3)");
		}
		return jLabel19;
	}

	private JLabel getJLabel16() {
		if (jLabel16 == null) {
			jLabel16 = new JLabel();
			jLabel16.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel16.setBounds(215, 286, 195, 25);
			jLabel16.setText("Peso Normal");
		}
		return jLabel16;
	}

	private JLabel getJLabel15() {
		if (jLabel15 == null) {
			jLabel15 = new JLabel();
			jLabel15.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel15.setBounds(215, 235, 195, 25);
			jLabel15.setText("Bajo Peso");
		}
		return jLabel15;
	}

	private JLabel getJLabel14() {
		if (jLabel14 == null) {
			jLabel14 = new JLabel();
			jLabel14.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel14.setBounds(58, 438, 124, 25);
			jLabel14.setText("40");
		}
		return jLabel14;
	}

	private JLabel getJLabel13() {
		if (jLabel13 == null) {
			jLabel13 = new JLabel();
			jLabel13.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel13.setBounds(58, 384, 124, 25);
			jLabel13.setText("30.0 a 39.9");
		}
		return jLabel13;
	}

	private JLabel getJLabel12() {
		if (jLabel12 == null) {
			jLabel12 = new JLabel();
			jLabel12.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel12.setBounds(58, 335, 124, 25);
			jLabel12.setText("25.0 a 29.9");
		}
		return jLabel12;
	}

	private JLabel getJLabel11() {
		if (jLabel11 == null) {
			jLabel11 = new JLabel();
			jLabel11.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel11.setBounds(58, 285, 124, 25);
			jLabel11.setText("18.5 a 24.9");
		}
		return jLabel11;
	}

	private JLabel getJLabel10() {
		if (jLabel10 == null) {
			jLabel10 = new JLabel();
			jLabel10.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel10.setBounds(58, 234, 124, 25);
			jLabel10.setText("Menor a 18.5");
		}
		return jLabel10;
	}

	private JLabel getJLabel9() {
		if (jLabel9 == null) {
			jLabel9 = new JLabel();
			jLabel9.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel9.setBounds(823, 177, 216, 25);
			jLabel9.setText("Descripción Habitual");
		}
		return jLabel9;
	}

	private JLabel getJLabel8() {
		if (jLabel8 == null) {
			jLabel8 = new JLabel();
			jLabel8.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel8.setBounds(472, 177, 300, 25);
			jLabel8.setText("Exceso de Peso en Kg Promedio");
		}
		return jLabel8;
	}

	private JLabel getJLabel7() {
		if (jLabel7 == null) {
			jLabel7 = new JLabel();
			jLabel7.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel7.setBounds(215, 178, 216, 25);
			jLabel7.setText("Clasificación de la OMS");
		}
		return jLabel7;
	}

	private JLabel getJLabel6() {
		if (jLabel6 == null) {
			jLabel6 = new JLabel();
			jLabel6.setFont(new Font("Tahoma", Font.PLAIN, 20));
			jLabel6.setBounds(58, 177, 124, 25);
			jLabel6.setText("IMC (en Kg)");
		}
		return jLabel6;
	}

	private JSeparator getJSeparator1() {
		if (jSeparator1 == null) {
			jSeparator1 = new JSeparator();
			jSeparator1.setBounds(58, 213, 1028, 10);
		}
		return jSeparator1;
	}

	private JSeparator getJSeparator0() {
		if (jSeparator0 == null) {
			jSeparator0 = new JSeparator();
			jSeparator0.setBounds(58, 156, 1028, 10);
		}
		return jSeparator0;
	}

	private JLabel getJLabel5() {
		if (resultadoLabel == null) {
			resultadoLabel = new JLabel();
			resultadoLabel.setFont(new Font("Dialog", Font.PLAIN, 21));
			resultadoLabel.setBounds(804, 64, 88, 25);
		}
		return resultadoLabel;
	}

	private JLabel getJLabel4() {
		if (jLabel4 == null) {
			jLabel4 = new JLabel();
			jLabel4.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel4.setBounds(662, 64, 132, 25);
			jLabel4.setText("Resultado:");
		}
		return jLabel4;
	}

	private JLabel getJLabel3() {
		if (jLabel3 == null) {
			jLabel3 = new JLabel();
			jLabel3.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel3.setBounds(519, 84, 86, 25);
			jLabel3.setText("Metros");
		}
		return jLabel3;
	}

	private JLabel getJLabel2() {
		if (jLabel2 == null) {
			jLabel2 = new JLabel();
			jLabel2.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel2.setBounds(519, 37, 40, 25);
			jLabel2.setText("Kg.");
		}
		return jLabel2;
	}

	private JTextField getJTextField1() {
		if (alturaTextField == null) {
			alturaTextField = new JTextField();
			alturaTextField.setFont(new Font("Tahoma", Font.PLAIN, 21));
			alturaTextField.setBounds(427, 83, 82, 25);
		}
		return alturaTextField;
	}

	private JTextField getJTextField0() {
		if (pesoTextField == null) {
			pesoTextField = new JTextField();
			pesoTextField.setFont(new Font("Tahoma", Font.PLAIN, 21));
			pesoTextField.setBounds(426, 36, 83, 25);
		}
		return pesoTextField;
	}

	private JLabel getJLabel1() {
		if (jLabel1 == null) {
			jLabel1 = new JLabel();
			jLabel1.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel1.setBounds(267, 84, 117, 25);
			jLabel1.setText("Altura:");
		}
		return jLabel1;
	}

	private JLabel getJLabel0() {
		if (jLabel0 == null) {
			jLabel0 = new JLabel();
			jLabel0.setFont(new Font("Dialog", Font.PLAIN, 21));
			jLabel0.setBounds(267, 37, 159, 25);
			jLabel0.setText("Peso Actual:");
		}
		return jLabel0;
	}

	//////////////////////////***************************************/////////////////////////////////////
	
	
	public void setActionListeners(final MasaController masaController)
	{
		alturaTextField.setActionCommand(Comandos.CALCULAR_MASA.toString());
		alturaTextField.addActionListener(masaController);
		
		btnCap.setActionCommand(Comandos.CAPTURA.toString());
		btnCap.addActionListener(masaController);
	}
	
	public String getPeso()
	{
		return pesoTextField.getText();
	}

	public String getAltura()
	{
		return alturaTextField.getText();
	}
	
	public void setAlturaPeso(String resultado)
	{
		resultadoLabel.setText(resultado);
	}

	public void setColorResult(float resultado) {
		
		jLabel10.setForeground(Color.black);
		jLabel15.setForeground(Color.black);
		jLabel20.setForeground(Color.black);
		jLabel25.setForeground(Color.black);

		jLabel11.setForeground(Color.black);
		jLabel16.setForeground(Color.black);
		jLabel21.setForeground(Color.black);
		jLabel26.setForeground(Color.black);

		jLabel12.setForeground(Color.black);
		jLabel17.setForeground(Color.black);
		jLabel22.setForeground(Color.black);
		jLabel27.setForeground(Color.black);
	
		jLabel13.setForeground(Color.black);
		jLabel18.setForeground(Color.black);
		jLabel23.setForeground(Color.black);
		jLabel28.setForeground(Color.black);

		jLabel14.setForeground(Color.black);
		jLabel19.setForeground(Color.black);
		jLabel24.setForeground(Color.black);
		jLabel29.setForeground(Color.black);
		jLabel30.setForeground(Color.black);
		
		if (resultado < 18.5) {
			jLabel10.setForeground(Color.red);
			jLabel15.setForeground(Color.red);
			jLabel20.setForeground(Color.red);
			jLabel25.setForeground(Color.red);
		}
		if ((resultado >= 18.5) && (resultado < 25)) {
			jLabel11.setForeground(Color.red);
			jLabel16.setForeground(Color.red);
			jLabel21.setForeground(Color.red);
			jLabel26.setForeground(Color.red);
		}
		if ((resultado >= 25) && (resultado < 30)) {
			jLabel12.setForeground(Color.red);
			jLabel17.setForeground(Color.red);
			jLabel22.setForeground(Color.red);
			jLabel27.setForeground(Color.red);
		}
		if ((resultado >= 30) && (resultado < 40)) {
			jLabel13.setForeground(Color.red);
			jLabel18.setForeground(Color.red);
			jLabel23.setForeground(Color.red);
			jLabel28.setForeground(Color.red);
		}
		if (resultado >= 40) {
			jLabel14.setForeground(Color.red);
			jLabel19.setForeground(Color.red);
			jLabel24.setForeground(Color.red);
			jLabel29.setForeground(Color.red);
			jLabel30.setForeground(Color.red);
		}
	}
	private JButton getBtnCap() {
		if (btnCap == null) {
			btnCap = new JButton("CAP");
			btnCap.setFont(new Font("Tahoma", Font.PLAIN, 16));
			btnCap.setBounds(1060, 11, 78, 23);
		}
		return btnCap;
	}
}
